//
//  ViewController.m
//  KKBarViewDemo
//
//  Created by liaozhenming on 16/3/26.
//  Copyright © 2016年 liaozhenming. All rights reserved.
//

#import "ViewController.h"

#import "KKBarChartView.h"
#import "KKLineChartView.h"

@interface ViewController () <KKBarChartViewDataSource, KKLineChartViewDataSource> {
    
    KKLineChartView *_lineChartView;
    KKBarChartView *_barChartView;
    
    NSArray *_valueArray;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *rootView = self.view;
//    _barChartView = [[KKBarChartView alloc] initWithFrame: CGRectMake(20, 100, CGRectGetWidth(rootView.bounds) - 40, 300)];
//    _barChartView.backgroundColor = [UIColor colorWithWhite: 0.1 alpha:0.3];
//    _barChartView.dataSource = self;
//    [rootView addSubview: _barChartView];
    
    
    _lineChartView = [[KKLineChartView alloc] initWithFrame: CGRectMake(20, 100, CGRectGetWidth(rootView.bounds) - 40, 300)];
    _lineChartView.backgroundColor = [UIColor colorWithWhite: 0.1 alpha:0.3];
    _lineChartView.dataSource = self;
    [rootView addSubview: _lineChartView];
    
    
//    _valueArray = @[@(9),@(2),@(6),@(13),@(1),@(5),@(7),@(9),@(16),@(44),@(11),@(14),@(8),@(6),@(2),@(5),@(20),@(15),@(12),@(9),@(5),@(2),@(17),@(11)];
    _valueArray = @[@[@(9),@(2),@(6),@(13)],@[@(4),@(5),@(6),@(7)],@[@(20),@(18),@(16),@(14)],@[@(8),@(10),@(12),@(14)],@[@(3),@(5),@(7),@(9)],@[@(14),@(15),@(16),@(17)]];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear: animated];
    
    [_barChartView reloadData];
    
    [_lineChartView reloadData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - KKBarChartViewDataSource methods

- (NSArray*)valuesOfLateralAxisInBarChartView:(KKBarChartView *)chartView {
    return _valueArray;
}

- (NSString *)chartView:(KKBarChartView *)chartView lateralAxisTitleAtIndex:(NSInteger)index {
    
    return  [NSString stringWithFormat: @"%@月",@(index + 1)];
}

#pragma mark - KKLineChartViewDataSource methods

- (NSArray*)valuesOfLateralAxisInLineChartView:(KKLineChartView *)chartView {
    
    return @[@(5),@(15),@(25),@(22),@(18),@(16),@(12),@(14),@(18),@(17),@(22),@(23),@(26),@(27),@(30),@(21),@(32),@(33),@(21),@(1),@(15),@(19),@(14),@(12)];
}

@end
